package cn.stylefeng.guns.modular.gridsystem.enums.temp;

import cn.stylefeng.guns.modular.gridsystem.temperature.service.BizTemperatureConfigService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.util.EnumMap;
import java.util.Map;

/**
 * @Author S-CH
 * @Date 2024/6/24 13:59
 * @Version 1.0
 */
@Configuration
public class TempConfigUtil {
    private  BizTemperatureConfigService bizTemperatureConfigService;
    @Autowired
    public void setBizTemperatureConfigService(BizTemperatureConfigService bizTemperatureConfigService) {
        this.bizTemperatureConfigService = bizTemperatureConfigService;
    }
    // 使用EnumMap来保持类型安全和映射效率
    private static Map<TempDictType, String> values = new EnumMap<>(TempDictType.class);

    @PostConstruct
    public void init() {
        bizTemperatureConfigService.list().forEach(item -> {
            TempDictType anEnum = TempDictType.getEnum(item.getDictType());
            if (anEnum!=null) {
                values.put(anEnum, item.getDictValue());
            }
        });
    }

    public static String getValue(TempDictType type) {
        return values.get(type);
    }


    public static void setValue(TempDictType type, String value) {
        values.put(type, value);
    }

}
